import random


class RandomizedSet:

    def __init__(self):
        self.h = dict()
        self.i = 0
        self.f = dict()

    def insert(self, val: int) -> bool:
        if val not in self.h:
            self.h[val] = self.i
            self.f[self.i] = val
            self.i += 1
            return True
        return False

    def remove(self, val: int) -> bool:
        if val in self.h:
            pos = self.h.pop(val)
            if pos + 1 == self.i:
                self.f.pop(pos)
            else:
                v = self.f.pop(self.i - 1)
                self.h[v] = pos
                self.f[pos] = v
            self.i -= 1
            return True
        return False

    def getRandom(self) -> int:
        r = random.randrange(0, self.i)
        return self.f[r]


# Your RandomizedSet object will be instantiated and called as such:
# obj = RandomizedSet()
# param_1 = obj.insert(val)
# param_2 = obj.remove(val)
# param_3 = obj.getRandom()